apiready = function() {
	var header = $api.byId('header');
    $api.fixStatusBar(header);
	
	// status bar style
    api.setStatusBarStyle({
        style: 'light'
    });

	// show main
	var width = api.winWidth;
    var headerPos = $api.offset(header);
    var height = api.winHeight - headerPos.h;
    
    api.openFrame({
        name: 'group-create-con',
        url: 'group-create-con.html',
        rect: {
            x: 0,
            y: headerPos.h,
            w: width,
            h: height
        },
        bounces: true,
        opaque: true,
        vScrollBarEnabled: false
    });
};

function uploadGroupLogo() {
	
	api.getPicture({
    		sourceType: 'library',
        encodingType: 'png',
        mediaValue: 'pic',
        destinationType: 'url',
        allowEdit: false,
        quality: 30,
    }, function(ret, err){ 
        if (ret) {
        		
        		api.showProgress({
        			title: '正在上传图片...',
        			modal: false
    			});
        		
        		uploadImage(ret.data, function(ret, err) {
        			if (ret) {
	        			if (ret.path) {
	        				var new_bg = "background-image: url('"+ret.path+"')";
	        				$api.css($api.byId('group-create-header'), new_bg);
	        				
	        				$api.setStorage("create-group-banner", ret.path);
	        			} else {
	        				// TODO
	        			}		 

	        			api.hideProgress();
        			} else {
        				alert(err.msg);
        				
        				api.hideProgress();
        			}
        		});
        		
        		

       } else {
              api.alert({msg:err.msg});
       };
   });
}


// 判断是否收取入团费
var need_fee = false;
function switchFee(it){

	$api.toggleCls(it, 'on');
	
	if($api.hasCls(it, 'on')) {
		need_fee = true;
	} else {
		need_fee = false;
	}
}

function openGroupCreateCaptain() {
	var group_name = $api.byId('name').value;
	var group_intro = $api.byId('intro').value;
	var group_fee = $api.byId('fee').value;
	var group_need_fee = need_fee;
	
	if (group_name == "") {
		api.toast({
	        msg:'请输入跑团名称'
        });
        
		return false;
	}
	
	if (group_intro == "") {
		api.toast({
	        msg:'请输入跑团简介'
        });
        
		return false;
	}

	if (need_fee && group_fee == '' ) {
		api.toast({
	        msg:'请输入入团费用'
        });
        
		return false;
	} 
	
	if (!$api.getStorage('create-group-banner')) {
		api.toast({
	        msg:'请上传跑团图片'
        });
        
		return false;
	}
	
	$api.setStorage("create-group-name", group_name);
	$api.setStorage("create-group-intro", group_intro);
	$api.setStorage("create-group-fee", group_fee);
	$api.setStorage("create-group-needfee", group_need_fee);

	api.openWin({
        name: 'group-create-captain',
        url: '../group-create-captain/group-create-captain.html'
    });
}